package com.wdc.binarytree;

/**
 * 力扣226翻转二叉树
 */
@SuppressWarnings("all")
public class LeetCode226 {
    public TreeNode invertTree(TreeNode root) {
            if (root == null ){
                return root;
            }
            fn(root);
            return root;
    }

    public static void fn(TreeNode root){

        if (root == null){
            return;
        }

        //交换左右孩子
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;

        //递归进行交换
        fn(root.left);
        fn(root.right);

    }

}
